

#include <scene/portal.h>
#include <scene/sector.h>
#include <assert.h>


cePortal::cePortal (ceSector* sector0, ceSector* sector1)
	: iObject ()
{
  CE_OBJECT_CONSTR;
	_sector[0] = 0;
	_sector[1] = 0;

  CE_SET(_sector[0], sector0);
  CE_SET(_sector[1], sector1);
}

cePortal::~cePortal ()
{
  CE_UNSET(_sector[0]);
  CE_UNSET(_sector[1]);
}

void cePortal::SetSector (unsigned i, ceSector* sector)
{
	assert (i <= 1);
  CE_SET(_sector[i], sector);
}

ceSector* cePortal::GetSector (unsigned i)
{
	assert (i <= 1);
	return _sector[i];
}

const ceSector* cePortal::GetSector (unsigned i) const
{
	assert (i <= 1);
	return _sector[i];
}

ceSector* cePortal::GetSector (const ceSector* sector)
{
	if (sector == _sector[0]) 
		{
			return _sector[1];
		}
	else if (sector == _sector[1])
		{
			return _sector[0];
		}
	return 0;
}

const ceSector* cePortal::GetSector (const ceSector* sector) const
{
	if (sector == _sector[0]) 
		{
			return _sector[1];
		}
	else if (sector == _sector[1])
		{
			return _sector[0];
		}
	return 0;
}


void cePortal::SetOpen (bool open)
{
	_open = open;
}

bool cePortal::IsOpen () const
{
	return _open;
}


void cePortal::ClearVertices ()
{
	_vertices.clear ();
}

void cePortal::AddVector (const ceVector3f& vertex)
{
	_vertices.push_back (vertex);
}

const ceVector3f* cePortal::GetVertices () const
{
	return _vertices.data();
}

unsigned cePortal::GetNumberOfVertices () const
{
	return _vertices.size();
}
